import hashlib
import random
import re

ALL_CHARS = '1234567890qwertyuiopasdfghjklzxcvbnm'
USERNAME_PATTERN = re.compile(r'^\w{6,20}$')


def check_username(username):
    matcher = USERNAME_PATTERN.fullmatch(username)
    return matcher is not None

def check_poassword(password):
    pass



def to_md5_hex(content):
    """生成MD5摘要"""
    return hashlib.md5(content.encode()).hexdigest()

def random_text(length=4):
    """生成指定长度的随机字符"""
    return ''.join(random.choices(ALL_CHARS, k=length))

